package LeetCode.leetcode203;

public class Review1 {
    public ListNode removeElements(ListNode head, int val) {
        if (head == null) return null;
        //虚拟头结点
        ListNode virtualNode = new ListNode();
        virtualNode.next = head;
        ListNode p = virtualNode;
        while (p.next != null){
            if (p.next.val == val){
                p.next = p.next.next;
            }else {
                p = p.next;
            }
        }
        return virtualNode.next;
    }
}
